<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2023/8/29
 * Time: 15:20
 */

namespace app\api\controller;

use think\Db;

class Bogoods extends Base
{
    public $user_id; // 用户ID
    public $page; // 页码
    public $create_time;

    /**
     * 异地登录验证
     * @return string
     */
    public function __construct()
    {
        $this->user_id = input('user_id');
        $this->page = input('page') ? input('page') : 1;
        $this->create_time = date('Y-m-d H:i:s');
        $time = input('time');
        $value = input('value');
        $reqKey = input('reqKey');
        $auth = $this->checkAll($this->user_id, $time, $value, $reqKey);
        if($auth == 112){
            echo json_encode(['status' => 301, 'msg' => $this->otherLogin]);
            exit;
        }elseif($auth == 110){
            echo json_encode(['status' => 302, 'msg' => $this->frost]);
            exit;
        }elseif($auth == 2111){
            echo json_encode(['status' => 303, 'msg' => $this->del]);
            exit;
        }
    }

    /**
     * 点即丽首页商品展示
     * bg_type       1 花样青青   2 脖脸皮
     * page          页码
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function indexGoods(){
        $bg_type = input('bg_type') ? input('bg_type') : 1; // 1 花样青青   2 脖脸皮
        $where = [
//            'bg_is_commend' => 2,
            'bg_status'     => 1,
            'bg_type'       => $bg_type
        ];

        $goods = $this->boGoodsList($where);
        if($goods){
            return json(['status' => 200, 'msg' => $goods]);
        }else{
            return json(['status' => 200, 'msg' => []]);
        }
    }

    //******************************************    公共方法  *****************************************//
    /**
     * 脖脸皮商品列表
     * @param $where     查询条件
     * @return bool|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    private function boGoodsList($where = []){
        $data = Db::table('up_bo_goods')
            ->where($where)
            ->field('bg_id, bg_name, bg_thumb, bg_spec, bg_stock, bg_sale_number, 
            bg_show_salenumber, bg_show_stock, bg_price, bg_old_price')
            ->page($this->page, 10)
            ->order('bg_sort desc, bg_time desc')
            ->select();
        return $data;
    }
}